/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bulkmailer.email.scanner;

import bulkmailer.beans.AccountSettings;
import bulkmailer.beans.ServerSettings;
import bulkmailer.db.DBConnector;

import java.sql.Connection;
import java.util.TreeSet;
import java.util.logging.Level;
import org.apache.log4j.Logger;

public class ScannerThread extends Thread {

    public ServerSettings serverSettings = null;
    public AccountSettings accountSettings = null;
    Connection con = null;
    TreeSet set = new TreeSet();

    public ScannerThread(ServerSettings serverSettings, AccountSettings accountSettings) {
        this.serverSettings = serverSettings;
        this.accountSettings = accountSettings;
    }

    @Override
    public void run() {
        try {
            MailScanner mailScanner = new MailScanner();
            con = DBConnector.getConnection(DBConnector.SCHEMA_NAME);
            if (con == null) {
                Logger.getRootLogger().error("database connection failure");
                return;
            } else {
                Logger.getRootLogger().debug("datbase connection successful");
            }
            mailScanner.setCon(con);
            mailScanner.fetchMails(this.accountSettings, this.serverSettings);

        } catch (Exception ex) {
            Logger.getRootLogger().error(ex.toString());
        }
    }
}
